package com.hospital.diagnosis.module.config;

import com.hospital.diagnosis.module.hanlder.AiDiagnosisHandler;
import com.hospital.diagnosis.module.hanlder.ChatServerHandler;
import com.hospital.diagnosis.module.hanlder.WebSocketHandshakeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Component
@EnableWebSocket
public class AiWebSocketConfig implements WebSocketConfigurer {
    @Autowired
    private AiDiagnosisHandler aiDiagnosisHandler;
    @Autowired
    private ChatServerHandler chatServerHandler;
    @Autowired
    private WebSocketHandshakeInterceptor handshakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(aiDiagnosisHandler, "/ws/ai")
                .addHandler(chatServerHandler, "/ws/chat")
                .addInterceptors(handshakeInterceptor)
                .setAllowedOrigins("*");
    }
}
